package com.bms.client.schedule;
import com.bms.client.mapper.ChuFangGuanLiMapper;
import com.bms.client.mapper.DuiWaiXinXiJiaoLiuMapper;
import com.bms.client.mapper.HeZuoJiHuaGuanLiMapper;
import com.bms.client.mapper.LaiFangGuanLiMapper;
import com.bms.client.pojo.DuiWaiXinXiJiaoLiu;
import com.bms.client.service.ChuFangGuanLiService;
import com.bms.client.service.DuiWaiXinXiJiaoLiuService;
import com.bms.client.service.HeZuoJiHuaGuanLiService;
import com.bms.client.service.LaiFangGuanLiService;
import com.bms.client.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zcx
 * @version 1.0
 * @description ShouYinGuanLiSchedule.java
 * @date 2021/2/28 15:55
 */
@Component
public class ShouYinGuanLiSchedule {
    // fixedRate = 1000 代表每隔1秒执行一次这个方法
    @Resource
    private LaiFangGuanLiMapper laiFangGuanLiMapper;
    @Resource(name = "laiFangGuanLiService")
    private LaiFangGuanLiService laiFangGuanLiService;
    @Resource
    private ChuFangGuanLiMapper chuFangGuanLiMapper;
    @Resource(name = "chuFangGuanLiService")
    private ChuFangGuanLiService chuFangGuanLiService;
    @Resource
    private HeZuoJiHuaGuanLiMapper heZuoJiHuaGuanLiMapper;
    @Resource(name = "heZuoJiHuaGuanLiService")
    private HeZuoJiHuaGuanLiService heZuoJiHuaGuanLiService;
    @Resource
    private DuiWaiXinXiJiaoLiuMapper duiWaiXinXiJiaoLiuMapper;
    @Resource
    private DuiWaiXinXiJiaoLiuService duiWaiXinXiJiaoLiuService;
    @Resource
    private RedisUtils redisUtils;


//    @Scheduled(cron = "0 0 * * * *")
    @Scheduled(initialDelayString="1000", fixedRate = 1000*60*60)
//    @Scheduled(cron = "0 0 23 * * ? *")//每天的23时 统计一次
    public void executeScheduledTask() {
        try {
            System.out.println("日志");
            DuiWaiXinXiJiaoLiu duiWaiXinXiJiaoLiu=new DuiWaiXinXiJiaoLiu();
            SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String format = dateFormat.format(new Date(System.currentTimeMillis()));
            duiWaiXinXiJiaoLiu.setRiQi(new Date(System.currentTimeMillis()));
            duiWaiXinXiJiaoLiu.setHeZuoJiHuaShuLiang(heZuoJiHuaGuanLiMapper.chaXunCiShuByTime(format));
            duiWaiXinXiJiaoLiu.setLaiFangShuLiang(laiFangGuanLiMapper.chaXunCiShuByTime(format));
            duiWaiXinXiJiaoLiu.setChuFangShuLiang(chuFangGuanLiMapper.chaXunCiShuByTime(format));
            duiWaiXinXiJiaoLiuMapper.xinZeng(duiWaiXinXiJiaoLiu);

            DuiWaiXinXiJiaoLiu duiWaiXinXiJiaoLiu1 =(DuiWaiXinXiJiaoLiu) duiWaiXinXiJiaoLiuService.chaXunById(duiWaiXinXiJiaoLiu.getId()).get("obj");
            Map<String,String> map=new HashMap<>();
            map.put("riQi",dateFormat1.format(duiWaiXinXiJiaoLiu1.getRiQi()));
            redisUtils.redisInsert("duiWaiXinXiJiaoLiu",map,duiWaiXinXiJiaoLiu1.getId().toString(),duiWaiXinXiJiaoLiu1);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("日志创建失败");
        }
    }
}

